package com.liangxy.news.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * Utility class for version operations
 */
public class VersionUtils {
    
    /**
     * Get current app version name
     * @param context Application context
     * @return App version name
     */
    public static String getVersionName(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return "1.0";
        }
    }
    
    /**
     * Get current app version code
     * @param context Application context
     * @return App version code
     */
    public static int getVersionCode(Context context) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return 1;
        }
    }
    
    /**
     * Check if a new version is available
     * @param currentVersion Current version code
     * @param newVersion New version code
     * @return True if new version is available, false otherwise
     */
    public static boolean isNewVersionAvailable(int currentVersion, int newVersion) {
        return newVersion > currentVersion;
    }
} 